package com.tools.cleanmaster.ui.card.ui;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.tools.cleanmaster.R;

/**
 * Created by wen.yu.gang on 2018/7/5
 */
public class EmptyLayout extends FrameLayout {
    private ImageView mImageView;
    private TextView mTipsView;

    public EmptyLayout(Context cxt, AttributeSet attrs) {
        super(cxt, attrs);

        TypedArray a = cxt.obtainStyledAttributes(attrs, R.styleable.EmptyLayout);
        Drawable image = a.getDrawable(R.styleable.EmptyLayout_image);
        CharSequence tips = a.getText(R.styleable.EmptyLayout_tips);
        a.recycle();

        setupViews(cxt);
        if (image != null) {
            mImageView.setImageDrawable(image);
        }
        if (tips != null) {
            mTipsView.setText(tips);
        }
    }

    private void setupViews(Context cxt) {
        LayoutInflater inflater = LayoutInflater.from(cxt);
        inflater.inflate(R.layout.empty_layout, this, true);

        mImageView = findViewById(R.id.image);
        mTipsView = findViewById(R.id.tips);
    }

    public void setImage(int resId) {
        mImageView.setImageResource(resId);
    }

    public void setTips(CharSequence tips) {
        mTipsView.setText(tips);
    }

    public void setTips(int resId) {
        mTipsView.setText(resId);
    }

    public void setOnClickListener(OnClickListener listener) {
        mImageView.setOnClickListener(listener);
    }
}
